using System;
using System.Text;
using NUnit.Framework;
using dnA.Math;

namespace dnA.dnAtests.Math 
{
    public class TestHelper
    {
        public static void TestRelativeError(ComplexDouble expected, ComplexDouble approx, double acceptableError)
        {
            TestRelativeError(expected.Real, approx.Real, acceptableError);
            TestRelativeError(expected.Imag, approx.Imag, acceptableError);
        }

        public static void TestRelativeError(double expected, double approx, double acceptableError)
        {
            double relativeError;
            if (System.Math.Abs(expected) < 1e-13)
            {
                relativeError = System.Math.Abs(approx - expected);
            }
            else
            {
                relativeError = System.Math.Abs((approx - expected) / expected);
            }
            Assert.Less(relativeError, acceptableError);
        }

		public static void TestRelativeError(ComplexFloat expected, ComplexFloat approx, float acceptableError)
		{
			TestRelativeError(expected.Real, approx.Real, acceptableError);
			TestRelativeError(expected.Imag, approx.Imag, acceptableError);
		}

		public static void TestRelativeError(float expected, float approx, float acceptableError)
		{
			double relativeError;
			if (System.Math.Abs(expected) < 1e-3)
			{
				relativeError = System.Math.Abs(approx - expected);
			}
			else
			{
				relativeError = System.Math.Abs((approx - expected) / expected);
			}
			Assert.Less(relativeError, acceptableError);
		}
    }
}
